<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>购买会员 - 嵌入式学习大本营</title>
    <style>
        body { background: #0a0e17; color: #e0f7fa; font-family: 'Microsoft YaHei', sans-serif; text-align: center; padding: 60px;}
        .box { background: #112233; border-radius: 16px; display: inline-block; padding: 40px 60px; box-shadow: 0 0 20px #00f7ff44;}
        h1 { color: #00f7ff; }
        .btn { margin-top: 30px; padding: 12px 30px; background: linear-gradient(to right, #00f7ff, #0066ff); color: #0a0e17; border: none; border-radius: 8px; font-size: 18px; font-weight: bold; cursor: pointer;}
        .btn:hover { background: #00f7ff; color: #0066ff;}
    </style>
</head>
<body>
    <div class="box">
        <h1>无权限访问</h1>
        <p>您当前没有访问该课程的权限，请购买会员或联系管理员开通权限。</p>
        <button class="btn" onclick="window.location.href='login.html'">登录/注册</button>
        <button class="btn" onclick="window.location.href='qianrushi.html'">返回首页</button>
    </div>
    <script>
        // 显示用户到期时间
        async function showUserStatus() {
            try {
                const res = await fetch('/api/user');
                if (!res.ok) return;
                const data = await res.json();
                if (data.user && data.user.expire_date) {
                    let expire = data.user.expire_date === '2099-12-31' ? '永久有效' : data.user.expire_date;
                    document.getElementById('userStatus').textContent = `到期时间：${expire}`;
                } else if (data.user) {
                    document.getElementById('userStatus').textContent = `到期时间：无限制`;
                }
            } catch {}
        }
        showUserStatus();

        async function checkCoursePermission(course) {
            // 课程路径如 'c_language'，可根据实际传参
            const res = await fetch(`/api/check-course/${course}`);
            const data = await res.json();
            if (data.access) {
                // 有权限，跳转
                window.location.href = `./doc1/${course}/index.html`;
            } else {
                if (data.type === 'login_required') {
                    alert('请先登录');
                    window.location.href = '/index/user/login';
                } else {
                    alert('无权限访问该课程');
                    window.location.href = '/index/user/goumai';
                }
            }
        }
    </script>
</body>
</html> 